/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.math.ColorRGBA;
import com.jme3.niftygui.NiftyJmeDisplay;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.NiftyEventSubscriber;
import de.lessvoid.nifty.controls.RadioButton;
import de.lessvoid.nifty.controls.RadioButtonGroupStateChangedEvent;
import de.lessvoid.nifty.controls.RadioButtonStateChangedEvent;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;

/**
 * @date 2024年7月12日16点56分
 * @author JohnKkk
 */
public class NiftyGuiRadioButton extends SimpleApplication implements ScreenController{

    private Nifty m_Nifty;
    
    public static void main(String[] args) {
        NiftyGuiRadioButton niftyGuiLabel = new NiftyGuiRadioButton();
        niftyGuiLabel.start();
    }
    
    @Override
    public void simpleInitApp() {
        // 设置默认背景色
        getViewPort().setBackgroundColor(ColorRGBA.DarkGray);
        
        // 初始化Nifty
        NiftyJmeDisplay niftyDisplay = NiftyJmeDisplay.newNiftyJmeDisplay(
                assetManager,
                inputManager,
                audioRenderer,
                guiViewPort);
        m_Nifty = niftyDisplay.getNifty();
        // 将NiftyGUI显示对象添加到JME3中
        guiViewPort.addProcessor(niftyDisplay);
        
        m_Nifty.fromXml("Interface/NiftyGuiRadioButton.xml", "screen0");
        
        // 禁用flyCam并显示鼠标
        flyCam.setEnabled(false);
        inputManager.setCursorVisible(true);
    }
    
    @NiftyEventSubscriber(id="radioGroup0")
    public final void onRadioButtonGroup0Event(final String id, final RadioButtonGroupStateChangedEvent event){
        System.out.println("当前选中:" + event.getSelectedId() + ",上一个选中的是:" + event.getPreviousSelectedId());
    }
    
    @NiftyEventSubscriber(id="radiobutton1")
    public void onOption3Changed(final String id, final RadioButtonStateChangedEvent event) {
      System.out.println("RadioButton [" + event.getRadioButton().getId() + "] is selected [" + event.isSelected() + "]");
    }

    @Override
    public void bind(Nifty nifty, Screen screen0) {
        RadioButton radioButton1 = screen0.findElementById("radiobutton1").getNiftyControl(RadioButton.class);
        System.out.println("radioButton:" + radioButton1.isActivated());
        radioButton1.select();
    }

    @Override
    public void onStartScreen() {
    }

    @Override
    public void onEndScreen() {
    }
    
}
